Micron Document
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SparkN0de-git | SparkN0de |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Commit 9f30d0fef631ceab1b361a2e65abeb109deafed9


Parents : 44c6526
Author : Ivan <ivan@quad4.io>
Signature : Signature validation error
Date : 2026-04-18T00:28:47-05:00

fix(tests): fix peering key rejection test to avoid CI flakes by ensuring valid peer selection

Changes

1 files changed, 13 insertions(+), 2 deletions(-)


Diff

diff --git a/tests/backend/test_lxmf_communication.py b/tests/backend/test_lxmf_communication.py
index a1a723f9..ce6edc84 100644
--- a/tests/backend/test_lxmf_communication.py
+++ b/tests/backend/test_lxmf_communication.py
@@ -164,14 +164,25 @@ class TestStampSolving:
assert LXStamper.validate_peering_key(peer_id, stamp, 2)
def test_peering_key_rejected_for_wrong_id(self):
+ """Pick a peer_b for which the stamp does not accidentally satisfy the
+ target cost. With cost=8 there is a 1/256 chance of a random workblock
+ producing a hash that already meets the threshold, so retry until we
+ get a peer_b that genuinely fails validation. This avoids CI flakes
+ without inflating stamp_cost (and therefore generation time).
+ """
peer_a = os.urandom(32)
- peer_b = os.urandom(32)
stamp, _ = LXStamper.generate_stamp(
peer_a,
stamp_cost=8,
expand_rounds=LXStamper.WORKBLOCK_EXPAND_ROUNDS_PEERING,
)
- assert not LXStamper.validate_peering_key(peer_b, stamp, 8)
+ for _ in range(64):
+ peer_b = os.urandom(32)
+ if peer_b == peer_a:
+ continue
+ if not LXStamper.validate_peering_key(peer_b, stamp, 8):
+ return
+ pytest.fail("could not find a peer_b that rejects peer_a's stamp")
def test_pn_stamp_valid_transient_data(self):
from LXMF.LXMessage import LXMessage


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────